from django.db import models
from datetime import date


# Create your models here.

class Book(models.Model):
    title = models.CharField("书名", max_length=50, unique=True)
    author = models.CharField("作者", max_length=10)
    pub_date = models.DateField("上架日期", default=date(year=2000, month=1, day=1))
    info = models.TextField("简介", null=True, blank=True)
    category = models.ForeignKey("Category", on_delete=models.CASCADE, default=1)

    def __str__(self):
        return self.title


class Category(models.Model):
    title = models.CharField("类别", max_length=10, unique=True)
    info = models.TextField("详情", null=True, blank=True)

    def __str__(self):
        return self.title
